class Solution {
    String[] mapString = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
    public List<String> letterCombinations(String digits) {
        List<String> list = new ArrayList<>();
        StringBuffer curStr = new StringBuffer();
        if(digits.length() == 0){
            return list;
        }
        dfs(digits, list, curStr, 0);
        return list;
    }

    public void dfs(String digits, List<String> list, StringBuffer curStr, int curDepth){
        if(curDepth == digits.length()){
            list.add(curStr.toString());
            return ;
        }

        int curMapIndex = digits.charAt(curDepth) - '0';
        String curMap = mapString[curMapIndex];

        for(int i = 0; i < curMap.length(); i++){
            dfs(digits, list, curStr.append(curMap.charAt(i)),curDepth + 1);
            curStr.deleteCharAt(curStr.length() - 1);
        }
    }
}